<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        table {
            border-collapse: collapse;
            margin: 0 auto;
        }

        td,
        th {
            border: 1px solid black;
            width: 90px;
            height: 30px;
            text-align: center;

        }

        thead tr th {
            background-color: gainsboro;
        }
    </style>
</head>

<body>
    <p><a href="https://www.bilibili.com/video/BV1Sy4y1C7ha?p=238&vd_source=480c28921b1b6c12cb33e4a6f0a94947">视频链接</a>
    </p>
    <table>
        <thead>
            <tr>
                <th>姓名</th>
                <th>科目</th>
                <th>成绩</th>
                <th>操作</th>
        </thead>
        <tbody>
            <!-- 动态增减 -->
        </tbody>
    </table>
    <script>
        let dates = [{
            name: '张三',
            subject: 'javascript',
            score: 98
        }, {
            name: '李斯',
            subject: 'javascript',
            score: 99
        }, {
            name: '王宁',
            subject: 'javascript',
            score: 100
        }, {
            name: '吴非',
            subject: 'javascript',
            score: 96
        }, {
            name: '李欢',
            subject: 'javascript',
            score: 90
        }, {
            name: '孙金瑶',
            subject: 'javascript',
            score: 100
        }];
        //往tbody里面创建行 有几个人通过数组长度来创建
        let tbody = document.querySelector('tbody');
        for (let i = 0; i < dates.length; i++) {
            //创建行tr
            let tr = document.createElement('tr');
            //放到body里面
            tbody.appendChild(tr);
            //行里面创建单元格，取决于属性的个个数
            for (let k in dates[i]) {
                //创建单元格
                let td = document.createElement('td');
                //把对象里面的属性值data s[i][k]  object[k](得到的是属性值)给td
                td.innerHTML = dates[i][k];
                tr.appendChild(td);
            }
            //创建有删除二字的单元格
            let td = document.createElement('td');
            td.innerHTML = '<a href="javascript:;">删除</a>';
            tr.appendChild(td);
        }
        //删除操作
        let as = document.querySelectorAll('a');
        for (let i = 0; i < as.length; i++) {
            as[i].onclick = function () {
                // tr= this.parentNode.parentNode
                tbody.removeChild(this.parentNode.parentNode);
            }
        }
    </script>
</body>

</html>